package my.db;

import java.util.List;

/**
 * 分页类
 */
public class Page<T> {

	// 当前页码: 从1开始
	private int page = 1;
	// 每页大小
	private int limit = 20;

	// 当前页的数据
	private List<T> data;
	// 总共多少条记录
	private long count = -1;

	// 排序
	private String field;
	private String type;

	public Page() {
	}

	public Page(int page) {
		this.page = page;
	}

	public Page(int page, int limit) {
		this.page = page;
		this.limit = limit;
	}

	/**
	 * 获得共多少页
	 */
	public int getTotalPage() {
		if (count % limit == 0) {
			return (int) count / limit;
		}
		return (int) count / limit + 1;
	}

	/**
	 * 下一页的页码
	 */
	public int getNextPage() {
		if (page == getTotalPage()) {
			return page;
		}
		return page + 1;
	}

	/**
	 * 上一页的页码
	 */
	public int getPrePage() {
		if (page == 1) {
			return 1;
		}
		return page - 1;
	}

	public int getCode() {
		return 0;
	}

	public int getPage() {
		return page;
	}

	public void setPage(int page) {
		this.page = page;
	}

	public int getLimit() {
		return limit;
	}

	public void setLimit(int limit) {
		this.limit = limit;
	}

	public List<T> getData() {
		return data;
	}

	public void setData(List<T> data) {
		this.data = data;
	}

	public long getCount() {
		return count;
	}

	public void setCount(long count) {
		this.count = count;
	}

	public String getField() {
		return field;
	}

	public void setField(String field) {
		this.field = field;
	}

	public String getType() {
		return type;
	}

	public void setType(String type) {
		this.type = type;
	}

}
